package com.yangtao.springbootfreemarker.config;

import com.yangtao.core.shiro.service.impl.ShiroSecurityService;
import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class FreemarkerConfig {

	@Value("${system.version}")
	private String version;
	@Autowired
	public freemarker.template.Configuration configuration;
	@Autowired
	private ShiroSecurityService securityService;

	@PostConstruct
	public void setFreemarkerConfig() {
		try {
			configuration.setSharedVariable("v", version); // 设置共享版本号
			configuration.setSharedVariable("securityService", securityService); // 将权限管理放入全局设置
		} catch (TemplateModelException e) {
			e.printStackTrace();
		}
	}
}
